package schema

type Response struct {
	// 既可以包含错误，也可以在正确时包含一些附加信息
	Msg  interface{} `json:"msg" swaggertype:"string" example:"This is an info/warning/error string"`
	Data interface{} `json:"data" swaggertype:"object"`
	Page interface{} `json:"page,omitempty" swaggertype:"object"`
	Code int         `json:"code"`
}

type ResponseErr struct {
	Msg  interface{} `json:"msg" swaggertype:"string" example:"This is an error string"`
	Data interface{} `json:"data" swaggertype:"object"`
}

// 暂时还是用error做status
func CreateResp(code int, data interface{}, err error) Response {
	if err != nil {
		return Response{Code: code, Msg: err.Error(), Data: data}
	}
	return Response{Code: code, Data: data}
}

func CreatePageResp(code int, data, pager interface{}, err error) Response {
	if err != nil {
		return Response{Code: code, Msg: err.Error(), Data: data, Page: pager}
	}
	return Response{Code: code, Data: data, Page: pager}
}
